<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">印章使用申请表</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_seal_input" class="panel-body form-horizontal form-padding">
                <input type="hidden" name="keyId" id="keyId" value="${seal.id}" />
                <div class="form-group">
                    <label class="col-md-2 control-label">印章使用类型<i class="fa fa-asterisk txt-color-red"></i>
                        <span id="useTypeSpan" style="display: none">${seal.useType}</span>
                    </label>
                    <div class="col-md-6">

                        <div class="radio">
                            <!-- Inline radio buttons -->
                            <input type="radio" name="useType" id="useType1Selected" class="magic-radio" value="1"
                            <c:if test="${seal.useType eq 1}"> checked="checked"</c:if> >
                            <label for="useType1Selected">内部使用</label>

                            <input type="radio" name="useType" id="useType2Selected" class="magic-radio" value="2"
                            <c:if test="${seal.useType eq 2}"> checked="checked"</c:if> >
                            <label for="useType2Selected">外借使用</label>

                        </div>
                    </div>
                </div>

                <div class="form-group div-Hidden">
                    <label class="col-md-2 control-label">预计归还时间<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                            <div class="input-group date">
                                <input type="text" class="form-control" id="datPlanReturn" name="datPlanReturn" placeholder="请选择预计归还时间"
                                value=<fmt:formatDate pattern="yyyy-MM-dd" value="${seal.datPlanReturn}" /> >
                                <span class="input-group-addon"><i class="ti-calendar"></i></span>
                            </div>
                    </div>
                </div>

                <div class="form-group div-Hidden">
                    <label class="col-md-2 control-label">实际归还时间</label>
                    <div class="col-md-6">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${seal.datFactReturn}" /></p>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">印章名称<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <select id="sealDictItemId" name="sealDictItemId" class="form-control">
                            <option></option>
                            <c:forEach var="item" items="${sealDictItems}" varStatus="status">
                                <option value="${item.id}" <c:if test="${item.id == seal.sealDictItem.id}"> selected="selected"</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">使用事由<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="text" id="useReason" name="useReason" class="form-control" placeholder="请输入使用事由" value="${seal.useReason}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">盖章份数<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <input type="number" id="numSeal" name="numSeal" class="form-control" placeholder="请输入盖章份数( 份数应是一个正整数 )" value="${seal.numSeal}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">附件上传</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="fileAttachment" placeholder="" type="file" >
                        <input name="hiddenFiles" id="hiddenFilesAttachment" type="hidden" value="${seal.fileAttachment}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">提交人</label>
                    <div class="col-md-2">
                        <p class="form-control-static">${seal.creater.name}</p>
                    </div>
                    <label class="col-md-2 control-label">提交日期</label>
                    <div class="col-md-2">
                        <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${seal.dateApply}" /></p>
                    </div>
                </div>
            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

            <div class="panel-footer">
                <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                    <i class="fa fa-lg fa-mail-reply"></i> 返回视图
                </a>
                <c:if test="${seal.numStatus==0 && user.id==seal.creater.id}">
                    <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存表单 </a>
                    <a class="btn btn-warning" id="btn-submit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交表单 </a>
                </c:if>
            </div>
        </div>
    </div>
</div>

<script>

    // 日期选择
    $('.input-group.date').datepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        todayHighlight: true,
        language: 'zh-CN'
    });

    // 印章字典列表下拉框
    $("#sealDictItemId").select2({
        placeholder: "请选择一个印章",
        allowClear: true
    });

    // 附件上传
    inputLoad({
        objId:"fileAttachment",
        entityName:"fileAttachment",
        sourceId:"hiddenFilesAttachment"
    });

    //校验
    function infoValidate() {
        var tmp = "";

        var useType = $("#useTypeSpan").text();
        if(useType == "2"){
            tmp = $("input#datPlanReturn").val();
            if(!tmp){
                __toastr_error("请选择预计归还时间！");
                return false;
            }
        }

        tmp = $("select#sealDictItemId").val();
        if(!tmp){
            __toastr_error("请选择要使用的印章！");
            return false;
        }

        tmp = $("input#useReason").val();
        if(!tmp){
            __toastr_error("请输入使用事由！");
            return false;
        }

        tmp = $("input#numSeal").val();
        if(!tmp){
            __toastr_error("请输入盖章份数！");
            return false;
        }

        return true;
    }

    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_seal_input", "<%=path%>/activiti/seal/save");
                            returnToHashUrl();
                        }
                )
            }
    );

    //提交
    $("#btn-submit-common").click(
            function(e) {
                var $valid = infoValidate();
//                console.log("v:"+$valid);
                if(!$valid) return false;

                __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                        function () {
                            __form_save("form_seal_input", "<%=path%>/activiti/seal/submit");
                            returnToHashUrl();
                        }
                )
            }
    );

    //返回视图
    $("#apply-re-common").click(returnToHashUrl);

    // 加载完成后执行
    $(function(){
        $("#useType1Selected").click(function(){
            $("#useTypeSpan").text("1");
            $(".div-Hidden").hide();
        })

        $("#useType2Selected").click(function(){
            $("#useTypeSpan").text("2");
            $(".div-Hidden").show();
        })

        if($("#useTypeSpan").text()=="1"){
            $(".div-Hidden").hide();
        }

    })

</script>




